package com.bicon.botu.mall.order.api;

import com.bicon.botu.core.base.common.Constants;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.core.base.common.utils.StringUtils;
import com.bicon.botu.mall.order.service.IGoodsOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单管理移动端接口
 *
 * @auther liushujie
 * @date 2018-03-16
 */
@Slf4j
@RestController
@RequestMapping("/V2.0.0/api/goodsOrder")
public class GoodsOrderApiV2 extends BaseController {

    @Autowired
    private IGoodsOrderService iGoodsOrderService;


    /**
     * 根据订单状态获取订单列表
     * <p>
     * 我的订单-全部、待付款、代发货、待收货、待评价
     *
     * @param userId  用户id
     * @param status  订单状态
     * @param current 当前页
     * @param size    每页条数
     * @return
     */
    @RequestMapping(value = "/getUserOrderListByStatus")
    public BaseResult getUserOrderListByStatus(@RequestParam String userId, String status, @RequestParam int current, @RequestParam int size) {
        if (StringUtils.isEmpty(userId)) {
            return new BaseResult(Constants.RESPONSE_CODE_400, Constants.RESPONSE_MESSAGE_400);
        }
        return new BaseResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200, iGoodsOrderService.myOrder(userId, status, current, size));
    }

    /**
     * 查询单个订单详情信息
     *
     * @param userId  用户Id
     * @param orderId 订单号
     * @return
     */
    @RequestMapping(value = "/getOrderDetails")
    public BaseResult getOrderDetails(@RequestParam String userId, @RequestParam String orderId) {
        if (StringUtils.isEmpty(userId) && StringUtils.isEmpty(orderId)) {
            return new BaseResult(Constants.RESPONSE_CODE_400, Constants.RESPONSE_MESSAGE_400);
        }
        return new BaseResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200, iGoodsOrderService.getOrderDetails(userId, orderId));
    }


    /**
     * 根据条件查询订单
     *
     * @param userId 用户Id
     * @param word   商品名称
     * @return BaseResult 订单列表
     */
    @RequestMapping(value = "/queryOrder")
    public BaseResult queryOrder(@RequestParam String userId, String word) {
        if (StringUtils.isEmpty(userId)) {
            return new BaseResult(Constants.RESPONSE_CODE_400, Constants.RESPONSE_MESSAGE_400);
        }
        return new BaseResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200, iGoodsOrderService.queryOrderByGoodsName(userId, word));
    }

    /**
     * 删除订单
     *
     * @param orderId 订单id
     * @param userId  用户id
     * @return
     */
    @RequestMapping(value = "/deleteOrder", method = RequestMethod.POST)
    public BaseResult deleteOrder(@RequestParam String orderId, @RequestParam String userId) {
        return iGoodsOrderService.deleteOrder(orderId, userId);
    }

    /**
     * 取消订单
     *
     * @param orderId 订单id
     * @param userId  用户id
     * @param cancel  取消订单原因
     * @return
     */
    @RequestMapping(value = "/cancelOrder")
    public BaseResult cancelOrder(@RequestParam String orderId, @RequestParam String userId, @RequestParam String cancel) {
        return iGoodsOrderService.cancelOrder(orderId, userId, cancel);
    }


}